package com.enlorenz.core.tag.base;

import java.io.IOException;
import java.util.List;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.TagSupport;

import com.enlorenz.common.util.DataDetUtils;

/**
 * 表格标签
 * 用于循环List
 */
public class ElzColumnTag extends CustomSimpleTagSupport {
	public static final String STATUS_NAME="statusName";
	public static final String VAR_NAME="varName";
	//选择模式
	private String selectMode=SELECT_MODE_MULTI;
	//主键名
	private String idKeys;
	public static final String SELECT_MODE_SINGLE="single";
	public static final String SELECT_MODE_MULTI="multi";
	
	//标签头
	private static String tagHead;
	//标签尾部
	private static String tagTail;
	//List名
	private String list;
	//List内元素名
	private String var;
	//List 编辑计数
	private String status;
	static{
		tagHead="<table id='table' class='table table-striped table-bordered mytable'>";
		tagTail="</table>";
	}
	
	public void doTag() throws JspException, IOException {
		//获取遍历的List
		List sourceList = (List)getPageContextAttr(list);
		writeJSP(tagHead);
		if(DataDetUtils.isCollectionEmpty(sourceList)){
			//没有任何数据的时候显示
			//writeJSP(findNo);
		}else{
			getJspContext().setAttribute(VAR_NAME, var);
			getJspContext().setAttribute(STATUS_NAME,status);
			Object totalRecords=getPageContextAttr("totalRecords");
			for(int i=0;i<sourceList.size();i++){
				Object object=sourceList.get(i);
				getJspContext().setAttribute(var, object);
				getJspContext().setAttribute(status, i);
				
				
				//输出标签体
	            getJspBody().invoke(null);
			}
			
			
		}
		getJspContext().getOut().write(tagTail);
		
	}
	
	
	public int doStartTag() throws JspException {
		
		return TagSupport.EVAL_PAGE;
	}
	
	
	public int doEndTag() throws JspException {
		
		
		
		return TagSupport.EVAL_PAGE;
	}

	public String getList() {
		return list;
	}

	public void setList(String list) {
		this.list = list;
	}

	public String getVar() {
		return var;
	}

	public void setVar(String var) {
		this.var = var;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}


	public String getSelectMode() {
		return selectMode;
	}


	public void setSelectMode(String selectMode) {
		this.selectMode = selectMode;
	}

	public String getIdKeys() {
		return idKeys;
	}

	public void setIdKeys(String idKeys) {
		this.idKeys = idKeys;
	}


	
}
